﻿using Max.PH5_2103A.Shopping.TEntityFrame.DAL;
using Max.PH5_2103A.Shopping.TEntityFrame.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Max.PH5_2103A.Shopping.TEntityFrame.Repository
{
    /// <summary>
    /// 工作单元实现
    /// </summary>
    public class UnitOWork : IUnitOfWork
    {

        public MyDbContext _context;

        public UnitOWork(MyDbContext context)
        {
            _context = context;
        }

        /// <summary>
        /// 获取内存中的上下文对象（为了用它来开启和提交事务）
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public MyDbContext GetContext()
        {
            return _context;
        }

        /// <summary>
        /// 提交上下文内存数据到数据库--同步
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public int SaveChanges()
        {
            return _context.SaveChanges();
        }
    }
}
